/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.platformservice.messaging;

/**
 * Provides methods for receiving message beans from across a message sink.
 *
 * @param <T> The type of message beans that can be received by this subscriber
 */
public interface IMessageSinkSubscriber<T extends IMessageBean> extends IMessageSinkClient<T>
{
    /**
     * Attempts to fetch a message from the backing message sink implementation, returning immediately with a null
     * if no message is fetchable.
     *
     * @return E, message fetched, or null if no message was in the message sink at the time of the request
     */
    T receiveImmediate();

    /**
     * Attempts to fetch a message from the backing message sink implementation, blocking for a predefined
     * period of time until a message arrives.
     *
     * @param milliseconds Number of milliseconds to wait
     * @return E, message fetched, or null if no message arrived in the message sink by the end of the
     *         predefined interval
     * @throws InterruptedException if interrupted while waiting
     */
    T receiveInterval(long milliseconds) throws InterruptedException;

    /**
     * Attempts to fetch a message from the backing message sink implementation, blocking for an indefinite period of
     * time until a message arrives in the sink.
     *
     * @return E, message fetched
     * @throws InterruptedException if interrupted while waiting
     */
    T receiveIndefinite() throws InterruptedException;
}
